package git.soulbgm.controller;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;

/**
 * Redis 控制器
 *
 * @author SoulBGM
 * @date 2022/11/12 19:16
 */
@RestController
@RequestMapping("redis")
public class RedisController {

    private final StringRedisTemplate redisTemplate;

    public RedisController(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @GetMapping("get/{key}")
    public String get(@PathVariable("key") String key) {
        String val = redisTemplate.opsForValue().get(key);
        return val == null ? "没有" + key + "的数据" : val;
    }

    @GetMapping("set")
    public String set(String key, String val) {
        redisTemplate.opsForValue().set(key, val);
        return "success";
    }

}
